package com.xc.dsocket.server.x3;

import cn.hutool.core.io.BufferUtil;
import cn.hutool.socket.nio.NioServer;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class S1 extends NioServer {
    public S1(int port) {
        super(port);
    }

    @Override
    protected void read(SocketChannel socketChannel) {
        System.out.println("out -- ");
        try {
            ByteBuffer buffer = ByteBuffer.allocateDirect(1024);
            int read = socketChannel.read(buffer);
            if(read > 0){
                buffer.flip();
                System.out.println(BufferUtil.readUtf8Str(buffer));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void write(SocketChannel socketChannel) {

    }

    public static void main(String[] args) {
        S1 s1 = new S1(8083);
        s1.listen();
    }
}
